home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-07-28 | 60.5 KB | 2,560 lines | [TEXT/KAHL] |
- /*
- File: OCEObjects2.cp
-
- Copyright: © 1991-1994 by Apple Computer, Inc.
- All rights reserved.
-
- Part of the AOCE Sample SMSAM Package. Consult the license
- which came with this software for your specific legal rights.
-
- */
-
-
-
- #ifndef __BLJSTANDARDINCLUDES__
- #include "BLJStandardIncludes.h"
- #endif
-
- #ifndef __OCEOBJECTS__
- #include "OCEObjects.h"
- #endif
-
- #ifndef __IOSTREAM__
- #include "IOStream.h"
- #endif
-
- #ifndef __STRING__
- #include "String.h"
- #endif
-
- #ifndef __SCRIPT__
- #include "Script.h" // for UpperText and LowerText
- #endif
-
- #ifndef __FILES__
- #include "Files.h" // for FSWrite & FSRead
- #endif
-
- #ifndef __DEBUGASSERT__
- #include "DebugAssert.h" // for ASSERT macros
- #endif
-
- #ifndef __NEWDELETE__
- #include "NewDelete.h"
- #endif
-
- #ifndef __THREADUTILITIES__
- #include "ThreadUtilities.h"
- #endif
-
- #ifndef __ABSTRACTFILE__
- #include "AbstractFile.h"
- #endif
-
- #pragma segment OCEObjects
-
- void SetOCEObjectsInternalValidityChecking ( Boolean state );
- Boolean GetOCEObjectsInternalValidityChecking ();
-
- /***********************************|****************************************/
- /***********************************|****************************************/
-
- unsigned short
- TRLI::GetPhysicalSize ( const PackedRLI* p )
- {
- return ( p ? p->dataLength : 0 ) + sizeof ( ProtoPackedRLI );
- }
-
- /***********************************|****************************************/
-
- unsigned short
- TRLI::GetPhysicalSizeOfPacked ( const RLI* r )
- {
- return r ? ::OCEPackedRLISize ( r ) : sizeof ( ProtoPackedRLI );
- }
-
- /***********************************|****************************************/
-
- PackedRLI*
- TRLI::Allocate ( unsigned short bytes )
- {
- PackedRLI* result = (PackedRLI*) FAILNewPtrClear ( bytes );
- result->dataLength = bytes - sizeof(ProtoPackedRLI);
-
- return result;
- }
-
- /***********************************|****************************************/
-
- PackedRLI*
- TRLI::Allocate ( const RLI* unpackedSource )
- {
- #if defined ( INTERNAL_CHECKS )
- ASSERT ( IsValid ( unpackedSource ) );
- #endif
- unsigned short packedSize = GetPhysicalSizeOfPacked ( unpackedSource );
- PackedRLI* packedDestination = Allocate ( packedSize );
- ASSERT_RETURN_ZERO ( packedDestination != nil );
- ASSERT_RETURN_ZERO ( ::OCEPackRLI ( unpackedSource, packedDestination, packedSize ) == noErr );
- return packedDestination;
- }
-
- /***********************************|****************************************/
-
- PackedRLI*
- TRLI::Allocate ( const PackedRLI* packedSource )
- {
- #if defined ( INTERNAL_CHECKS )
- ASSERT ( IsValid ( packedSource ) );
- #endif
- unsigned short packedSize = GetPhysicalSize ( packedSource );
- PackedRLI* packedDestination = Allocate ( packedSize );
- ASSERT_RETURN_ZERO ( packedDestination != nil );
- ::BlockMove ( packedSource, packedDestination, packedSize );
- return packedDestination;
- }
-
- /***********************************|****************************************/
-
- void
- TRLI::Deallocate ( PackedRLI*& p )
- {
- if ( p )
- {
- DeallocatePtr( (Ptr) p );
- #if defined ( INTERNAL_CHECKS )
- ASSERT ( MemError () == noErr );
- #endif
- p = nil;
- }
- }
-
- /***********************************|****************************************/
-
- void
- TRLI::Deallocate ()
- {
- InvalidateUnpacked ();
- Deallocate ( fPacked );
- }
-
- /***********************************|****************************************/
-
- void
- TRLI::ValidateUnpacked () const
- {
- if ( !fUnpacked )
- {
- #if defined ( INTERNAL_CHECKS )
- ASSERT ( IsValidInternal () );
- #endif
-
- if ( fPacked->dataLength == 0 )
- {
- // Create an 'empty' unpacked rli.
- ( (TRLI*) this)->fUnpacked->directoryName = nil;
- ( (TRLI*) this)->fUnpacked->discriminator.signature = 0;
- ( (TRLI*) this)->fUnpacked->discriminator.misc = 0;
- ( (TRLI*) this)->fUnpacked->dNodeNumber = 0;
- ( (TRLI*) this)->fUnpacked->path = nil;
- }
- else
- {
- ( (TRLI*) this )->fUnpacked = (RLI*) FAILNewPtrClear ( sizeof ( RLI ) );
-
-
- if ( OCEValidPackedRLI ( fPacked ) )
- ::OCEUnpackRLI ( fPacked, ( (TRLI*) this )->fUnpacked );
- else
- {
- keithDB ( "TRLI::ValidateUnpacked, fPacked is invalid." );
- }
- }
-
- #if defined ( INTERNAL_CHECKS )
- ASSERT ( IsValidInternal ( ( (TRLI*) this )->fUnpacked ) );
- #endif
- }
- }
-
- /***********************************|****************************************/
-
- Boolean
- TRLI::ValidateUnpackedAndCheck () const
- {
- ValidateUnpacked ();
- return IsValid ( ( (TRLI*) this )->fUnpacked );
- }
-
- /***********************************|****************************************/
-
- void
- TRLI::InvalidateUnpacked () const
- {
- if ( fUnpacked )
- {
- ::DeallocatePtr( (Ptr) fUnpacked );
- #if defined ( INTERNAL_CHECKS )
- ASSERT ( MemError () == noErr );
- #endif
- ( (TRLI*) this )->fUnpacked = nil;
- }
- }
-
- /***********************************|****************************************/
-
- Boolean
- TRLI::IsValid ( const RLI* r )
- {
- return ( r != nil ) && ::OCEValidRLI ( r );
- }
-
- /***********************************|****************************************/
-
- Boolean
- TRLI::IsValid ( const PackedRLI* p )
- {
- return ( p != nil ) && ::OCEValidPackedRLI ( p );
- }
-
- /***********************************|****************************************/
-
- #if defined ( INTERNAL_CHECKS )
-
- Boolean
- TRLI::IsValidInternal ( const RLI* p )
- {
- return !GetOCEObjectsInternalValidityChecking() || IsValid ( p );
- }
-
- /***********************************|****************************************/
-
- Boolean
- TRLI::IsValidInternal ( const PackedRLI* p )
- {
- return !GetOCEObjectsInternalValidityChecking() || IsValid ( p );
- }
-
- #endif
-
- /***********************************|****************************************/
-
- TRLI::TRLI ():
- fPacked ( nil ),
- fUnpacked ( nil )
- {
- RLI emptyRLI;
-
- memset(&emptyRLI, 0, sizeof(emptyRLI));
- DirectoryName directoryName;
- directoryName.dataLength = 0;
- emptyRLI.directoryName = 0;
-
- fPacked = Allocate ( &emptyRLI );
-
- #if defined ( INTERNAL_CHECKS )
- ASSERT ( IsValidInternal () );
- #endif
- }
-
- /***********************************|****************************************/
-
- TRLI::TRLI ( const RLI& rli ):
- fPacked ( Allocate ( &rli ) ),
- fUnpacked ( nil )
- {
- #if defined ( INTERNAL_CHECKS )
- ASSERT ( IsValidInternal () );
- #endif
- }
-
- /***********************************|****************************************/
-
- TRLI::TRLI ( const RLI* rli ):
- fPacked ( Allocate ( rli ) ),
- fUnpacked ( nil )
- {
- #if defined ( INTERNAL_CHECKS )
- ASSERT ( IsValidInternal () );
- #endif
- }
-
- /***********************************|****************************************/
-
- TRLI::TRLI ( const PackedRLI& rli ):
- fPacked ( Allocate ( &rli ) ),
- fUnpacked ( nil )
- {
- #if defined ( INTERNAL_CHECKS )
- ASSERT ( IsValidInternal () );
- #endif
- }
-
- /***********************************|****************************************/
-
- TRLI::TRLI ( const PackedRLI* rli ):
- fPacked ( Allocate ( rli ) ),
- fUnpacked ( nil )
- {
- #if defined ( INTERNAL_CHECKS )
- ASSERT ( IsValidInternal () );
- #endif
- }
-
- /***********************************|****************************************/
-
- TRLI::TRLI ( const TDirectory& directory, const TPathName& path, DNodeNum node ):
- fPacked ( nil ),
- fUnpacked ( nil )
- {
- RLI rli;
-
- rli.directoryName = (DirectoryName*) (const DirectoryName*) directory.GetName ();
- rli.discriminator = * (DirDiscriminator *) directory.GetDiscriminator ();
- rli.dNodeNumber = node;
- rli.path = (PackedPathName*) (const PackedPathName*) path;
-
- fPacked = Allocate ( &rli );
-
- #if defined ( INTERNAL_CHECKS )
- ASSERT ( IsValidInternal () );
- #endif
- }
-
- /***********************************|****************************************/
-
- TRLI::TRLI ( const TDirectory& directory, DNodeNum node ):
- fPacked ( nil ),
- fUnpacked ( nil )
- {
- RLI rli;
-
- rli.directoryName = (DirectoryName*) (const DirectoryName*) directory.GetName ();
- rli.discriminator = * ( DirDiscriminator *) directory.GetDiscriminator() ;
- rli.dNodeNumber = node;
- rli.path = nil;
-
- fPacked = Allocate ( &rli );
-
- #if defined ( INTERNAL_CHECKS )
- ASSERT ( IsValidInternal () );
- #endif
- }
-
- /***********************************|****************************************/
-
- TRLI::TRLI ( const TRLI& that ):
- fPacked ( Allocate ( that.fPacked ) ),
- fUnpacked ( nil )
- {
- #if defined ( INTERNAL_CHECKS )
- ASSERT ( IsValidInternal () );
- #endif
- }
-
- /***********************************|****************************************/
-
- TRLI::~TRLI ()
- {
- Deallocate ();
- }
-
- /***********************************|****************************************/
-
- TRLI&
- TRLI::operator = ( const TRLI& that )
- {
- if ( this != &that )
- {
- Deallocate ();
- fPacked = Allocate ( that.fPacked );
- #if defined ( INTERNAL_CHECKS )
- ASSERT ( IsValidInternal () );
- #endif
- }
-
- return *this;
- }
-
- /***********************************|****************************************/
-
- TRLI&
- TRLI::operator = ( const RLI& unpacked )
- {
- if ( fUnpacked != &unpacked )
- {
- Deallocate ();
- fPacked = Allocate ( &unpacked );
- #if defined ( INTERNAL_CHECKS )
- ASSERT ( IsValidInternal () );
- #endif
- }
-
- return *this;
- }
-
- /***********************************|****************************************/
-
- TRLI&
- TRLI::operator = ( const PackedRLI& packedSource )
- {
- if ( fPacked != &packedSource )
- {
- Deallocate ();
- fPacked = Allocate ( &packedSource );
- #if defined ( INTERNAL_CHECKS )
- ASSERT ( IsValidInternal () );
- #endif
- }
-
- return *this;
- }
-
- /***********************************|****************************************/
-
- Boolean
- TRLI::operator == ( const TRLI& that ) const
- {
- return ::OCEEqualPackedRLI ( fPacked, that.fPacked );
- }
-
- /***********************************|****************************************/
-
- Boolean
- TRLI::operator != ( const TRLI& that ) const
- {
- return !::OCEEqualPackedRLI ( fPacked, that.fPacked );
- }
-
- /***********************************|****************************************/
-
- Boolean
- TRLI::operator == ( const PackedRLI& that ) const
- {
- return ::OCEEqualPackedRLI ( fPacked, &that );
- }
-
- /***********************************|****************************************/
-
- Boolean
- TRLI::operator != ( const PackedRLI& that ) const
- {
- return !::OCEEqualPackedRLI ( fPacked, &that );
- }
-
- /***********************************|****************************************/
-
- Boolean
- TRLI::operator == ( const RLI& that ) const
- {
- #if defined ( INTERNAL_CHECKS )
- ASSERT_RETURN_ZERO ( IsValidInternal () );
- #endif
- ValidateUnpacked ();
- return OCEEqualRLI ( ( (TRLI*) this )->fUnpacked, &that );
- }
-
- /***********************************|****************************************/
-
- TRLI::operator const RLI* () const
- {
- ValidateUnpackedAndCheck ();
- return fUnpacked;
- }
-
- /***********************************|****************************************/
-
- TRLI::operator const RLI& () const
- {
- ValidateUnpacked ();
- return *fUnpacked;
- }
-
- /***********************************|****************************************/
-
- void
- TRLI::SetDirectory ( const TDirectory& directory )
- {
- #if defined ( INTERNAL_CHECKS )
- ASSERT_RETURN ( IsValidInternal () );
- #endif
- ValidateUnpacked ();
- fUnpacked->directoryName = (DirectoryName*) (const DirectoryName*) directory.GetName ();
- fUnpacked->discriminator = * ( DirDiscriminator *) directory.GetDiscriminator () ;
- PackedRLI* newPacked = Allocate ( fUnpacked );
- ASSERT_RETURN ( newPacked != nil );
- Deallocate ();
- fPacked = newPacked;
-
- #if defined ( INTERNAL_CHECKS )
- ASSERT ( IsValidInternal () );
- #endif
- }
-
- /***********************************|****************************************/
-
- Boolean
- TRLI::GetDirectory ( TDirectory& directory ) const
- {
- #if defined ( INTERNAL_CHECKS )
- ASSERT_RETURN_ZERO ( IsValidInternal () );
- #endif
- ValidateUnpacked ();
- ASSERT_RETURN_ZERO ( fUnpacked->directoryName != nil );
- directory.SetName ( TDirectoryName ( *fUnpacked->directoryName ) );
- directory.SetDiscriminator ( fUnpacked->discriminator );
- return true;
- }
-
- /***********************************|****************************************/
-
- const DirectoryName*
- TRLI::GetDirectoryName () const
- {
- #if defined ( INTERNAL_CHECKS )
- ASSERT_RETURN_ZERO ( IsValidInternal () );
- #endif
- ValidateUnpacked ();
- return fUnpacked->directoryName;
- }
-
- /***********************************|****************************************/
-
- const DirDiscriminator&
- TRLI::GetDirectoryDiscriminator () const
- {
- #if defined ( INTERNAL_CHECKS )
- ASSERT ( IsValidInternal () );
- #endif
- ValidateUnpacked ();
- return fUnpacked->discriminator;
- }
-
- /***********************************|****************************************/
-
- void
- TRLI::SetPathName ( const TPathName& path )
- {
- #if defined ( INTERNAL_CHECKS )
- ASSERT_RETURN ( IsValidInternal () );
- #endif
- ValidateUnpacked ();
- fUnpacked->path = (PackedPathName*) (const PackedPathName*) path;
- PackedRLI* newPacked = Allocate ( fUnpacked );
- ASSERT_RETURN ( newPacked != nil );
- Deallocate ();
- fPacked = newPacked;
- #if defined ( INTERNAL_CHECKS )
- ASSERT ( IsValidInternal () );
- #endif
- }
-
- /***********************************|****************************************/
-
- Boolean
- TRLI::GetPathName ( TPathName& path ) const
- { Boolean result = false;
-
- #if defined ( INTERNAL_CHECKS )
- ASSERT_RETURN_ZERO ( IsValidInternal () );
- #endif
- ValidateUnpacked ();
-
- #if 1
- if ( fUnpacked->path != nil )
- {
- path = fUnpacked->path;
- result = true;
- }
-
- return result;
- #else
- ASSERT_RETURN_ZERO ( fUnpacked->path != nil );
- path = fUnpacked->path;
- return true;
- #endif
- }
-
- /***********************************|****************************************/
-
- const PackedPathName*
- TRLI::GetPathName () const
- {
- #if defined ( INTERNAL_CHECKS )
- ASSERT_RETURN_ZERO ( IsValidInternal () );
- #endif
- ValidateUnpacked ();
- return fUnpacked->path;
- }
-
- /***********************************|****************************************/
-
- void
- TRLI::SetNode ( DNodeNum node )
- {
- #if defined ( INTERNAL_CHECKS )
- ASSERT_RETURN ( IsValidInternal () );
- #endif
- ValidateUnpacked ();
- fUnpacked->dNodeNumber = node;
- PackedRLI* newPacked = Allocate ( fUnpacked );
- ASSERT_RETURN ( newPacked != nil );
- Deallocate ();
- fPacked = newPacked;
- #if defined ( INTERNAL_CHECKS )
- ASSERT_RETURN ( IsValidInternal () );
- #endif
- }
-
- /***********************************|****************************************/
-
- DNodeNum
- TRLI::GetNode () const
- {
- #if defined ( INTERNAL_CHECKS )
- ASSERT_RETURN_ZERO ( IsValidInternal () );
- #endif
- ValidateUnpacked ();
- return fUnpacked->dNodeNumber;
- }
-
- /***********************************|****************************************/
-
- Boolean
- TRLI::Write ( TAbstractFile& f ) const
- {
- #if defined ( INTERNAL_CHECKS )
- ASSERT_RETURN_ZERO ( IsValidInternal () );
- #endif
- unsigned short physicalSize = GetPhysicalSize ( fPacked );
- ASSERT_RETURN_ZERO ( f.Write ( physicalSize ) == noErr );
- ASSERT_RETURN_ZERO ( f.WriteDataIgnore ( fPacked, physicalSize ) == noErr );
- return true;
- }
-
- /***********************************|****************************************/
-
- Boolean
- TRLI::Read ( TAbstractFile& f )
- {
- unsigned short physicalSize = 0;
- ASSERT_RETURN_ZERO ( f.Read ( physicalSize ) == noErr );
- ASSERT_RETURN_ZERO ( physicalSize > sizeof ( ProtoPackedRLI ) );
- PackedRLI* p = Allocate ( physicalSize );
- ASSERT_RETURN_ZERO ( p != nil );
- ASSERT_RETURN_ZERO ( f.ReadDataIgnore ( p, physicalSize ) == noErr );
- Deallocate ();
- fPacked = p;
- #if defined ( INTERNAL_CHECKS )
- ASSERT_RETURN_ZERO ( IsValidInternal () );
- #endif
- return true;
- }
-
- /***********************************|****************************************/
-
- ostream&
- TRLI::operator >> ( ostream& s ) const
- {
- ValidateUnpacked ();
- s << "directory: " << * fUnpacked->directoryName;
- s << ", discriminator: " << fUnpacked->discriminator;
- s << ", dNodeNumber: " << fUnpacked->dNodeNumber;
- return s << ", path: " << *fUnpacked->path;
- }
-
- /***********************************|****************************************/
- /***********************************|****************************************/
-
- unsigned short
- TRecordID::GetPhysicalSize ( const PackedRecordID* p )
- {
- return ( p ? p->dataLength : 0 ) + sizeof ( ProtoPackedRecordID );
- }
-
- /***********************************|****************************************/
-
- unsigned short
- TRecordID::GetPhysicalSizeOfPacked ( const RecordID* r )
- {
- return r ? ::OCEPackedRecordIDSize ( r ) : sizeof ( ProtoPackedRecordID );
- }
-
- /***********************************|****************************************/
-
- PackedRecordID*
- TRecordID::Allocate ( unsigned short bytes )
- {
- return (PackedRecordID*) FAILNewPtrClear ( bytes );
- }
-
- /***********************************|****************************************/
-
- PackedRecordID*
- TRecordID::Allocate ( const RecordID* r )
- {
- #if defined ( INTERNAL_CHECKS )
- ASSERT ( IsValidInternal ( r ) );
- #endif
- unsigned short physicalSize = OCEPackedRecordIDSize ( r );
- PackedRecordID* packed = Allocate ( physicalSize );
- ASSERT_RETURN_ZERO ( packed != nil );
- ASSERT_RETURN_ZERO ( OCEPackRecordID ( r, packed, physicalSize ) == noErr );
- return packed;
- }
-
- /***********************************|****************************************/
-
- PackedRecordID*
- TRecordID::Allocate ( const PackedRecordID* p )
- {
- #if defined ( INTERNAL_CHECKS )
- ASSERT_RETURN_ZERO ( IsValidInternal ( p ) );
- #endif
- unsigned short physicalSize = GetPhysicalSize ( p );
- PackedRecordID* packed = Allocate ( physicalSize );
- ASSERT_RETURN_ZERO ( packed != nil );
- ::BlockMove ( p, packed, physicalSize );
- return packed;
- }
-
- /***********************************|****************************************/
-
- void
- TRecordID::Deallocate ( PackedRecordID*& p )
- {
- if ( p )
- {
- ::DeallocatePtr( (Ptr) p );
- #if defined ( INTERNAL_CHECKS )
- ASSERT ( MemError () == noErr );
- #endif
- p = nil;
- }
- }
-
- /***********************************|****************************************/
-
- void
- TRecordID::Deallocate ()
- {
- InvalidateUnpacked ();
- Deallocate ( fPacked );
- }
-
- /***********************************|****************************************/
-
- void
- TRecordID::ValidateUnpacked () const
- {
- if ( !fUnpacked )
- {
- #if defined ( INTERNAL_CHECKS )
- ASSERT_RETURN ( IsValidInternal ( fPacked ) );
- #endif
- ( (TRecordID*) this )->fUnpacked = (RecordID*) FAILNewPtrClear ( sizeof ( RecordID ) );
- ::OCEUnpackRecordID ( fPacked, ( (TRecordID*) this )->fUnpacked );
- }
- }
-
- /***********************************|****************************************/
-
- Boolean
- TRecordID::ValidateUnpackedAndCheck () const
- {
- ValidateUnpacked ();
- return IsValid ( fUnpacked );
- }
-
- /***********************************|****************************************/
-
- void
- TRecordID::InvalidateUnpacked () const
- {
- if ( fUnpacked )
- {
- ::DeallocatePtr( (Ptr) fUnpacked );
- #if defined ( INTERNAL_CHECKS )
- ASSERT ( MemError () == noErr );
- #endif
- ( (TRecordID*) this )->fUnpacked = nil;
- }
- }
-
- /***********************************|****************************************/
-
- Boolean
- TRecordID::IsValid ( const PackedRecordID* p )
- {
- return ( p != nil ) && ::OCEValidPackedRecordID ( p );
- }
-
- /***********************************|****************************************/
-
- Boolean
- TRecordID::IsValid ( const RecordID* p )
- {
- return ( p != nil );
- }
-
- /***********************************|****************************************/
-
- #if defined ( INTERNAL_CHECKS )
-
- Boolean
- TRecordID::IsValidInternal ( const RecordID* p )
- {
- return !GetOCEObjectsInternalValidityChecking() || IsValid ( p );
- }
-
- /***********************************|****************************************/
-
- Boolean
- TRecordID::IsValidInternal ( const PackedRecordID* p )
- {
- return !GetOCEObjectsInternalValidityChecking() || IsValid ( p );
- }
-
- #endif
-
- /***********************************|****************************************/
-
- TRecordID::TRecordID ():
- fPacked ( Allocate ( sizeof ( ProtoPackedRecordID ) ) ),
- fUnpacked ( nil )
- {
- }
-
- /***********************************|****************************************/
-
- TRecordID::TRecordID ( const TRecordID& that ):
- fPacked ( Allocate ( that.fPacked ) ),
- fUnpacked ( nil )
- {
- #if defined ( INTERNAL_CHECKS )
- ASSERT ( IsValidInternal () );
- #endif
- }
-
- /***********************************|****************************************/
-
- TRecordID::TRecordID ( const RecordID* r ):
- fPacked ( Allocate ( r ) ),
- fUnpacked ( nil )
- {
- #if defined ( INTERNAL_CHECKS )
- ASSERT ( IsValidInternal () );
- #endif
- }
-
- /***********************************|****************************************/
-
- TRecordID::TRecordID ( const PackedRecordID* r ):
- fPacked ( Allocate ( r ) ),
- fUnpacked ( nil )
- {
- #if defined ( INTERNAL_CHECKS )
- ASSERT ( IsValidInternal () );
- #endif
- }
-
- /***********************************|****************************************/
-
- TRecordID::TRecordID ( const RecordID& r ):
- fPacked ( Allocate ( &r ) ),
- fUnpacked ( nil )
- {
- #if defined ( INTERNAL_CHECKS )
- ASSERT ( IsValidInternal () );
- #endif
- }
-
- /***********************************|****************************************/
-
- TRecordID::TRecordID ( const PackedRecordID& r ):
- fPacked ( Allocate ( &r ) ),
- fUnpacked ( nil )
- {
- #if defined ( INTERNAL_CHECKS )
- ASSERT ( IsValidInternal () );
- #endif
- }
-
- /***********************************|****************************************/
-
- TRecordID::TRecordID ( const TRString& name, const TRString& type, const TPathName& path, const TDirectory& directory ):
- fPacked ( nil ),
- fUnpacked ( nil )
- {
- TRLI rli ( directory, path, 0 );
- RecordID r;
-
- r.rli = (PackedRLI*) (const PackedRLI*) rli;
- r.local.cid.source = 0;
- r.local.cid.seq = 0;
- r.local.recordName = (RString*) (const RString*) name;
- r.local.recordType = (RString*) (const RString*) type;
-
- fPacked = Allocate ( &r );
- #if defined ( INTERNAL_CHECKS )
- ASSERT ( IsValidInternal () );
- #endif
- }
-
- /***********************************|****************************************/
-
- TRecordID::TRecordID ( const TRString& name, const TRString& type, const TRLI& rli):
- fPacked ( nil ),
- fUnpacked ( nil )
- {
- RecordID r;
-
- r.rli = (PackedRLI*) (const PackedRLI*) rli;
- r.local.cid.source = 0;
- r.local.cid.seq = 0;
- r.local.recordName = (RString*) (const RString*) name;
- r.local.recordType = (RString*) (const RString*) type;
-
- fPacked = Allocate ( &r );
- #if defined ( INTERNAL_CHECKS )
- ASSERT ( IsValidInternal () );
- #endif
- }
-
- /***********************************|****************************************/
-
- TRecordID::TRecordID ( const TRString& name, const TRString& type, const DNodeNum node, const TDirectory& directory):
- fPacked ( nil ),
- fUnpacked ( nil )
- {
- TRLI rli ( directory, node );
- RecordID r;
-
- r.rli = (PackedRLI*) (const PackedRLI*) rli;
- r.local.cid.source = 0;
- r.local.cid.seq = 0;
- r.local.recordName = (RString*) (const RString*) name;
- r.local.recordType = (RString*) (const RString*) type;
-
- fPacked = Allocate ( &r );
- #if defined ( INTERNAL_CHECKS )
- ASSERT ( IsValidInternal () );
- #endif
- }
-
- /***********************************|****************************************/
-
- TRecordID::TRecordID ( const TCreationID& cid, const TPathName& path, const TDirectory& directory ):
- fPacked ( nil ),
- fUnpacked ( nil )
- {
- TRLI rli ( directory, path );
- RecordID r;
-
- r.rli = (PackedRLI*) (const PackedRLI*) rli;
- r.local.cid = (CreationID&) (const CreationID&) cid;
- r.local.recordName = nil;
- r.local.recordType = nil;
-
- fPacked = Allocate ( &r );
- #if defined ( INTERNAL_CHECKS )
- ASSERT ( IsValidInternal () );
- #endif
- }
-
- /***********************************|****************************************/
-
- TRecordID::TRecordID ( const TCreationID& cid, const DNodeNum node, const TDirectory& directory ):
- fPacked ( nil ),
- fUnpacked ( nil )
- {
- TRLI rli ( directory, node );
- RecordID r;
-
- r.rli = (PackedRLI*) (const PackedRLI*) rli;
- r.local.cid = (CreationID&) (const CreationID&) cid;
- r.local.recordName = nil;
- r.local.recordType = nil;
-
- fPacked = Allocate ( &r );
- #if defined ( INTERNAL_CHECKS )
- ASSERT ( IsValidInternal () );
- #endif
- }
-
- /***********************************|****************************************/
-
- TRecordID::TRecordID ( const TCreationID& cid, const TRLI& rli):
- fPacked ( nil ),
- fUnpacked ( nil )
- {
- RecordID r;
-
- r.rli = (PackedRLI*) (const PackedRLI*) rli;
- r.local.cid = (CreationID&) (const CreationID&) cid;
- r.local.recordName = nil;
- r.local.recordType = nil;
-
- fPacked = Allocate ( &r );
- #if defined ( INTERNAL_CHECKS )
- ASSERT ( IsValidInternal () );
- #endif
- }
-
- /***********************************|****************************************/
-
- TRecordID::TRecordID ( const LocalRecordID& localRecordID, const TPathName& p, const TDirectory& directory ):
- fPacked ( nil ),
- fUnpacked ( nil )
- {
- TRLI rli ( directory, p );
- RecordID r;
-
- r.rli = (PackedRLI*) (const PackedRLI*) rli;
- OCECopyCreationID(&localRecordID.cid, &r.local.cid);
- r.local.recordName = localRecordID.recordName;
- r.local.recordType = localRecordID.recordType;
-
- fPacked = Allocate ( &r );
- #if defined ( INTERNAL_CHECKS )
- ASSERT ( IsValidInternal () );
- #endif
- }
-
- /***********************************|****************************************/
-
- TRecordID::TRecordID ( const LocalRecordID& localRecordID, const DNodeNum node, const TDirectory& directory ):
- fPacked ( nil ),
- fUnpacked ( nil )
- {
- TRLI rli ( directory, node );
- RecordID r;
-
- r.rli = (PackedRLI*) (const PackedRLI*) rli;
- OCECopyCreationID(&localRecordID.cid, &r.local.cid);
- r.local.recordName = localRecordID.recordName;
- r.local.recordType = localRecordID.recordType;
-
- fPacked = Allocate ( &r );
- #if defined ( INTERNAL_CHECKS )
- ASSERT ( IsValidInternal () );
- #endif
- }
-
- /***********************************|****************************************/
-
- TRecordID::TRecordID ( const LocalRecordID& localRecordID, const TRLI& rli ):
- fPacked ( nil ),
- fUnpacked ( nil )
- {
- RecordID r;
-
- r.rli = (PackedRLI*) (const PackedRLI*) rli;
- OCECopyCreationID(&localRecordID.cid, &r.local.cid);
- r.local.recordName = localRecordID.recordName;
- r.local.recordType = localRecordID.recordType;
-
- fPacked = Allocate ( &r );
- #if defined ( INTERNAL_CHECKS )
- ASSERT ( IsValidInternal () );
- #endif
- }
-
- /***********************************|****************************************/
-
- TRecordID::~TRecordID ()
- {
- Deallocate ();
- }
-
- /***********************************|****************************************/
-
- TRecordID&
- TRecordID::operator = ( const RecordID* r )
- {
- #if defined ( INTERNAL_CHECKS )
- ASSERT ( r != nil );
- #endif
-
- if ( ASSERT ( fUnpacked != r ) )
- {
- Deallocate ();
- fPacked = Allocate ( r );
- #if defined ( INTERNAL_CHECKS )
- ASSERT ( IsValidInternal () );
- #endif
- }
-
- return *this;
- }
-
- /***********************************|****************************************/
-
- TRecordID&
- TRecordID::operator = ( const PackedRecordID* r )
- {
- if ( ASSERT ( fPacked != r ) )
- {
- Deallocate ();
- fPacked = Allocate ( r );
- #if defined ( INTERNAL_CHECKS )
- ASSERT ( IsValidInternal () );
- #endif
- }
-
- return *this;
- }
-
- /***********************************|****************************************/
-
- Boolean
- TRecordID::operator == ( const RecordID* r ) const
- {
- #if defined ( INTERNAL_CHECKS )
- if ( ASSERT ( IsValidInternal ( r ) ) )
- #endif
- if ( ASSERT ( ValidateUnpackedAndCheck () ) )
- return ::OCEEqualRecordID ( fUnpacked, r );
-
- return false;
- }
-
- /***********************************|****************************************/
-
- Boolean TRecordID::operator == ( const PackedRecordID* p ) const
- {
- #if defined ( INTERNAL_CHECKS )
- if ( ASSERT ( IsValidInternal ( p ) ) )
- #endif
- if ( ASSERT ( IsValidInternal ( fPacked ) ) )
- return ::OCEEqualPackedRecordID ( fPacked, p );
-
- return false;
- }
-
- /***********************************|****************************************/
-
- Boolean
- TRecordID::Adopt ( PackedRecordID* p )
- {
- ASSERT_RETURN_ZERO ( IsValid ( p ) && ( p != fPacked ) );
- Deallocate ();
- fPacked = p;
- return true;
- }
-
- /***********************************|****************************************/
-
- Boolean
- TRecordID::Set ( const RecordID* r )
- {
- // it is quite possible that the RecordID* passed in could
- // be our unpacked cache, so be careful about deleting or
- // invalidating or unpacked cache or deleting our pack storage!
-
- #if defined ( INTERNAL_CHECKS )
- ASSERT_RETURN_ZERO ( IsValidInternal ( r ) );
- #endif
- PackedRecordID* newPacked = Allocate ( r );
- #if defined ( INTERNAL_CHECKS )
- ASSERT_RETURN_ZERO ( IsValidInternal ( newPacked ) );
- #endif
- Deallocate ();
- fPacked = newPacked;
- return true;
- }
-
- /***********************************|****************************************/
-
- Boolean
- TRecordID::Set ( const PackedRLI* rli )
- {
- #if defined ( INTERNAL_CHECKS )
- ASSERT_RETURN_ZERO ( TRLI::IsValid ( rli ) );
- #endif
- ASSERT_RETURN_ZERO ( ValidateUnpackedAndCheck () );
- PackedRLI* prevRLI = fUnpacked->rli;
- fUnpacked->rli = (PackedRLI*) rli;
-
- if ( Set ( fUnpacked ) )
- {
- return true;
- }
- else
- {
- fUnpacked->rli = prevRLI;
- return false;
- }
- }
-
- /***********************************|****************************************/
-
- Boolean
- TRecordID::SetRecordName ( const TRString& string )
- {
- ASSERT_RETURN_ZERO ( ValidateUnpackedAndCheck () );
- RString* prevName = fUnpacked->local.recordName;
- fUnpacked->local.recordName = (RString*) (const RString*) string;
-
- if ( Adopt ( Allocate ( fUnpacked ) ) )
- {
- return true;
- }
- else
- {
- fUnpacked->local.recordName = prevName;
- return false;
- }
- }
-
- /***********************************|****************************************/
-
- Boolean
- TRecordID::GetRecordName ( TRString& string ) const
- {
- ASSERT_RETURN_ZERO ( ValidateUnpackedAndCheck () );
- string = fUnpacked->local.recordName;
- return true;
- }
-
- /***********************************|****************************************/
-
- Boolean
- TRecordID::SetRecordType ( const TRString& string )
- {
- ASSERT_RETURN_ZERO ( ValidateUnpackedAndCheck () );
- RString* prevType = fUnpacked->local.recordType;
- fUnpacked->local.recordType = (RString*) (const RString*) string;
-
- if ( Adopt ( Allocate ( fUnpacked ) ) )
- {
- return true;
- }
- else
- {
- fUnpacked->local.recordType = prevType;
- return false;
- }
- }
-
- /***********************************|****************************************/
-
- Boolean
- TRecordID::GetRecordType ( TRString& string ) const
- {
- ASSERT_RETURN_ZERO ( ValidateUnpackedAndCheck () );
- string = fUnpacked->local.recordType;
- return true;
- }
-
- /***********************************|****************************************/
-
- Boolean
- TRecordID::SetCreationID ( const TCreationID& cid )
- {
- ASSERT_RETURN_ZERO ( ValidateUnpackedAndCheck () );
- CreationID prevID = fUnpacked->local.cid;
- fUnpacked->local.cid = (CreationID&) (const CreationID&) cid;
-
- if ( Adopt ( Allocate ( fUnpacked ) ) )
- {
- return true;
- }
- else
- {
- fUnpacked->local.cid = prevID;
- return false;
- }
- }
-
- /***********************************|****************************************/
-
- Boolean
- TRecordID::GetCreationID ( TCreationID& cid ) const
- {
- ASSERT_RETURN_ZERO ( ValidateUnpackedAndCheck () );
- cid = fUnpacked->local.cid;
- return true;
- }
-
- /***********************************|****************************************/
-
- Boolean
- TRecordID::SetNode ( const DNodeNum node )
- {
- ASSERT_RETURN_ZERO ( ValidateUnpackedAndCheck () );
- TRLI rli ( fUnpacked->rli );
- rli.SetNode ( node );
- return Set ( rli );
- }
-
- /***********************************|****************************************/
-
- DNodeNum
- TRecordID::GetNode () const
- {
- ASSERT_RETURN_ZERO ( ValidateUnpackedAndCheck () );
- TRLI rli ( fUnpacked->rli );
- return rli.GetNode ();
- }
-
- /***********************************|****************************************/
-
- Boolean
- TRecordID::SetPathName ( const TPathName& path )
- {
- ASSERT_RETURN_ZERO ( ValidateUnpackedAndCheck () );
- TRLI rli ( fUnpacked->rli );
- rli.SetPathName ( path );
- return Set ( rli );
- }
-
- /***********************************|****************************************/
-
- Boolean
- TRecordID::GetPathName ( TPathName& path ) const
- {
- ASSERT_RETURN_ZERO ( ValidateUnpackedAndCheck () );
- TRLI rli ( fUnpacked->rli );
- return rli.GetPathName ( path );
- }
-
- /***********************************|****************************************/
-
- Boolean
- TRecordID::SetDirectory ( const TDirectory& directory )
- {
- ASSERT_RETURN_ZERO ( ValidateUnpackedAndCheck () );
- TRLI rli ( fUnpacked->rli );
- rli.SetDirectory ( directory );
- return Set ( rli );
- }
-
- /***********************************|****************************************/
-
- Boolean
- TRecordID::GetDirectory ( TDirectory& directory ) const
- {
- ASSERT_RETURN_ZERO ( ValidateUnpackedAndCheck () );
- TRLI rli ( fUnpacked->rli );
- return rli.GetDirectory ( directory );
- }
-
- /***********************************|****************************************/
-
- Boolean
- TRecordID::SetRLI ( const TRLI& rli )
- {
- return Set ( rli );
- }
-
- /***********************************|****************************************/
-
- Boolean
- TRecordID::GetRLI ( TRLI& rli ) const
- {
- ASSERT_RETURN_ZERO ( ValidateUnpackedAndCheck () );
- rli = TRLI ( fUnpacked->rli );
- return true;
- }
-
- /***********************************|****************************************/
-
- TRecordID::operator const RecordID* () const
- {
- ValidateUnpackedAndCheck ();
- return fUnpacked;
- }
-
- /***********************************|****************************************/
-
- TRecordID::operator const RecordID& () const
- {
- ValidateUnpacked ();
- return *fUnpacked;
- }
-
- /***********************************|****************************************/
-
- Boolean
- TRecordID::Write ( TAbstractFile& f ) const
- {
- #if defined ( INTERNAL_CHECKS )
- ASSERT_RETURN_ZERO ( IsValidInternal () );
- #endif
- unsigned short physicalSize = GetPhysicalSize ( fPacked );
- ASSERT_RETURN_ZERO ( f.Write ( physicalSize ) == noErr );
- ASSERT_RETURN_ZERO ( f.WriteDataIgnore ( fPacked, physicalSize ) == noErr );
- return true;
- }
-
- /***********************************|****************************************/
-
- Boolean
- TRecordID::Read ( TAbstractFile& f )
- {
- unsigned short physicalSize = 0;
- ASSERT_RETURN_ZERO ( f.Read ( physicalSize ) == noErr );
- ASSERT_RETURN_ZERO ( physicalSize >= sizeof ( ProtoPackedRecordID ) );
- PackedRecordID* newPacked = Allocate ( physicalSize );
- ASSERT_RETURN_ZERO ( newPacked != nil );
- ASSERT_RETURN_ZERO ( f.ReadDataIgnore ( newPacked, physicalSize ) == noErr );
- Deallocate ();
- fPacked = newPacked;
- #if defined ( INTERNAL_CHECKS )
- ASSERT_RETURN_ZERO ( IsValidInternal () );
- #endif
- return true;
- }
-
- /***********************************|****************************************/
-
- ostream&
- TRecordID::operator >> ( ostream& s ) const
- {
- if ( ASSERT ( ValidateUnpackedAndCheck () ) )
- {
- s << "rli: " << fUnpacked->rli;
- s << "\ncid: " << fUnpacked->local.cid;
- s << ", recordName: " << fUnpacked->local.recordName;
- s << ", recordType: " << fUnpacked->local.recordType;
- }
- else
- {
- s << "fPacked: " << fPacked;
- }
-
- return s;
- }
-
- /***********************************|****************************************/
- /***********************************|****************************************/
- /***********************************|****************************************/
- /***********************************|****************************************/
- /***********************************|****************************************/
-
- unsigned short
- TDSSpec::GetPhysicalSize ( const PackedDSSpec* p )
- {
- return ( p ? p->dataLength : 0 ) + sizeof ( ProtoPackedDSSpec );
- }
-
- /***********************************|****************************************/
-
- unsigned short
- TDSSpec::GetPhysicalSizeOfPacked ( const DSSpec* r )
- {
- return r ? ::OCEPackedDSSpecSize ( r ) : sizeof ( ProtoPackedDSSpec );
- }
-
- /***********************************|****************************************/
-
- PackedDSSpec*
- TDSSpec::Allocate ( unsigned short bytes )
- {
- return (PackedDSSpec*) FAILNewPtrClear ( bytes );
- }
-
- /***********************************|****************************************/
-
- PackedDSSpec*
- TDSSpec::Allocate ( const DSSpec* r )
- {
- #if defined ( INTERNAL_CHECKS )
- ASSERT ( IsValidInternal ( r ) );
- #endif
- unsigned short physicalSize = OCEPackedDSSpecSize ( r );
- PackedDSSpec* packed = Allocate ( physicalSize );
- ASSERT_RETURN_ZERO ( packed != nil );
- ASSERT_RETURN_ZERO ( OCEPackDSSpec ( r, packed, physicalSize ) == noErr );
- return packed;
- }
-
- /***********************************|****************************************/
-
- PackedDSSpec*
- TDSSpec::Allocate ( const PackedDSSpec* p )
- {
- #if defined ( INTERNAL_CHECKS )
- ASSERT_RETURN_ZERO ( IsValidInternal ( p ) );
- #endif
- unsigned short physicalSize = GetPhysicalSize ( p );
- PackedDSSpec* packed = Allocate ( physicalSize );
- ASSERT_RETURN_ZERO ( packed != nil );
- ::BlockMove ( p, packed, physicalSize );
- return packed;
- }
-
- /***********************************|****************************************/
-
- void
- TDSSpec::Deallocate ( PackedDSSpec*& p )
- {
- if ( p )
- {
- ::DeallocatePtr( (Ptr) p );
- #if defined ( INTERNAL_CHECKS )
- ASSERT ( MemError () == noErr );
- #endif
- p = nil;
- }
- }
-
- /***********************************|****************************************/
-
- void
- TDSSpec::Deallocate ()
- {
- InvalidateUnpacked ();
- Deallocate ( fPacked );
- }
-
- /***********************************|****************************************/
-
- void
- TDSSpec::ValidateUnpacked () const
- {
- if ( !fUnpacked )
- {
- #if defined ( INTERNAL_CHECKS )
- ASSERT_RETURN ( IsValidInternal ( fPacked ) );
- #endif
- ( (TDSSpec*) this )->fUnpacked = (DSSpec*) FAILNewPtrClear ( sizeof ( DSSpec ) );
- ( (TDSSpec*) this )->fUnpacked->entitySpecifier = (RecordID*) FAILNewPtrClear ( sizeof ( RecordID ) );
- ::OCEUnpackDSSpec ( fPacked, ( (TDSSpec*) this )->fUnpacked,
- ( (TDSSpec*) this )->fUnpacked->entitySpecifier );
- }
- }
-
- /***********************************|****************************************/
-
- Boolean
- TDSSpec::ValidateUnpackedAndCheck () const
- {
- ValidateUnpacked ();
- return IsValid ( fUnpacked );
- }
-
- /***********************************|****************************************/
-
- void
- TDSSpec::InvalidateUnpacked () const
- {
- if ( fUnpacked )
- {
- ::DeallocatePtr( (Ptr) fUnpacked->entitySpecifier );
- #if defined ( INTERNAL_CHECKS )
- ASSERT ( MemError () == noErr );
- #endif
- ::DeallocatePtr( (Ptr) fUnpacked );
- #if defined ( INTERNAL_CHECKS )
- ASSERT ( MemError () == noErr );
- #endif
- ( (TDSSpec*) this )->fUnpacked = nil;
- }
- }
-
- /***********************************|****************************************/
-
- Boolean
- TDSSpec::IsValid ( const PackedDSSpec* p )
- {
- return ( p != nil ) && ::OCEValidPackedDSSpec ( p );
- }
-
- /***********************************|****************************************/
-
- Boolean
- TDSSpec::IsValid ( const DSSpec* p )
- {
- return ( p != nil );
- }
-
- /***********************************|****************************************/
-
- #if defined ( INTERNAL_CHECKS )
-
- Boolean
- TDSSpec::IsValidInternal ( const DSSpec* p )
- {
- return ! GetOCEObjectsInternalValidityChecking() || IsValid ( p );
- }
-
- /***********************************|****************************************/
-
- Boolean
- TDSSpec::IsValidInternal ( const PackedDSSpec* p )
- {
- return ! GetOCEObjectsInternalValidityChecking() || IsValid ( p );
- }
-
- #endif
-
- /***********************************|****************************************/
-
- TDSSpec::TDSSpec ():
- fPacked ( Allocate ( sizeof ( ProtoPackedDSSpec ) ) ),
- fUnpacked ( nil )
- {
- }
-
- /***********************************|****************************************/
-
- TDSSpec::TDSSpec ( const TDSSpec& that ):
- fPacked ( Allocate ( that.fPacked ) ),
- fUnpacked ( nil )
- {
- #if defined ( INTERNAL_CHECKS )
- ASSERT ( IsValidInternal () );
- #endif
- }
-
- /***********************************|****************************************/
-
- TDSSpec::TDSSpec ( const DSSpec* r ):
- fPacked ( Allocate ( r ) ),
- fUnpacked ( nil )
- {
- #if defined ( INTERNAL_CHECKS )
- ASSERT ( IsValidInternal () );
- #endif
- }
-
- /***********************************|****************************************/
-
- TDSSpec::TDSSpec ( const PackedDSSpec* r ):
- fPacked ( Allocate ( r ) ),
- fUnpacked ( nil )
- {
- #if defined ( INTERNAL_CHECKS )
- ASSERT ( IsValidInternal () );
- #endif
- }
-
- /***********************************|****************************************/
-
- TDSSpec::TDSSpec ( const DSSpec& r ):
- fPacked ( Allocate ( &r ) ),
- fUnpacked ( nil )
- {
- #if defined ( INTERNAL_CHECKS )
- ASSERT ( IsValidInternal () );
- #endif
- }
-
- /***********************************|****************************************/
-
- TDSSpec::TDSSpec ( const PackedDSSpec& r ):
- fPacked ( Allocate ( &r ) ),
- fUnpacked ( nil )
- {
- #if defined ( INTERNAL_CHECKS )
- ASSERT ( IsValidInternal () );
- #endif
- }
-
-
- /***********************************|****************************************/
-
- TDSSpec::TDSSpec ( const TRString& name, const TRString& type, const TPathName& path, const TDirectory& directory,
- OSType extensionType, const void* extensionData, unsigned long extensionLength ):
- fPacked ( nil ),
- fUnpacked ( nil )
- {
- TRLI rli ( directory, path, 0 );
- RecordID r;
- DSSpec d;;
-
- r.rli = (PackedRLI*) (const PackedRLI*) rli;
- r.local.cid.source = 0;
- r.local.cid.seq = 0;
- r.local.recordName = (RString*) (const RString*) name;
- r.local.recordType = (RString*) (const RString*) type;
-
- d.entitySpecifier = & r;
- d.extensionType = extensionType;
- d.extensionSize = extensionLength;
- d.extensionValue = (char*) extensionData;
-
- fPacked = Allocate ( &d );
- #if defined ( INTERNAL_CHECKS )
- ASSERT ( IsValidInternal () );
- #endif
- }
-
- /***********************************|****************************************/
-
- TDSSpec::TDSSpec ( const TRString& name, const TRString& type, const TRLI& rli,
- OSType extensionType, const void* extensionData, unsigned long extensionLength ) :
- fPacked ( nil ),
- fUnpacked ( nil )
- {
- RecordID r;
- DSSpec d;;
-
- r.rli = (PackedRLI*) (const PackedRLI*) rli;
- r.local.cid.source = 0;
- r.local.cid.seq = 0;
- r.local.recordName = (RString*) (const RString*) name;
- r.local.recordType = (RString*) (const RString*) type;
-
- d.entitySpecifier = & r;
- d.extensionType = extensionType;
- d.extensionSize = extensionLength;
- d.extensionValue = (char*) extensionData;
-
- fPacked = Allocate ( &d );
- #if defined ( INTERNAL_CHECKS )
- ASSERT ( IsValidInternal () );
- #endif
- }
-
- /***********************************|****************************************/
-
- TDSSpec::TDSSpec ( const TRString& name, const TRString& type, const DNodeNum node, const TDirectory& directory,
- OSType extensionType, const void* extensionData, unsigned long extensionLength ):
- fPacked ( nil ),
- fUnpacked ( nil )
- {
- TRLI rli ( directory, node );
- RecordID r;
- DSSpec d;
-
- r.rli = (PackedRLI*) (const PackedRLI*) rli;
- r.local.cid.source = 0;
- r.local.cid.seq = 0;
- r.local.recordName = (RString*) (const RString*) name;
- r.local.recordType = (RString*) (const RString*) type;
-
- d.entitySpecifier = & r;
- d.extensionType = extensionType;
- d.extensionSize = extensionLength;
- d.extensionValue = (char*) extensionData;
-
- fPacked = Allocate ( &d );
- #if defined ( INTERNAL_CHECKS )
- ASSERT ( IsValidInternal () );
- #endif
- }
-
- /***********************************|****************************************/
-
- TDSSpec::TDSSpec ( const TCreationID& cid, const TPathName& path, const TDirectory& directory,
- OSType extensionType, const void* extensionData, unsigned long extensionLength ):
- fPacked ( nil ),
- fUnpacked ( nil )
- {
- TRLI rli ( directory, path );
- RecordID r;
- DSSpec d;;
-
- r.rli = (PackedRLI*) (const PackedRLI*) rli;
- r.local.cid = (CreationID&) (const CreationID&) cid;
- r.local.recordName = nil;
- r.local.recordType = nil;
-
- d.entitySpecifier = & r;
- d.extensionType = extensionType;
- d.extensionSize = extensionLength;
- d.extensionValue = (char*) extensionData;
-
- fPacked = Allocate ( &d );
- #if defined ( INTERNAL_CHECKS )
- ASSERT ( IsValidInternal () );
- #endif
- }
-
- /***********************************|****************************************/
-
- TDSSpec::TDSSpec ( const TCreationID& cid, const DNodeNum node, const TDirectory& directory,
- OSType extensionType, const void* extensionData, unsigned long extensionLength ):
- fPacked ( nil ),
- fUnpacked ( nil )
- {
- TRLI rli ( directory, node );
- RecordID r;
- DSSpec d;;
-
- r.rli = (PackedRLI*) (const PackedRLI*) rli;
- r.local.cid = (CreationID&) (const CreationID&) cid;
- r.local.recordName = nil;
- r.local.recordType = nil;
-
- d.entitySpecifier = & r;
- d.extensionType = extensionType;
- d.extensionSize = extensionLength;
- d.extensionValue = (char*) extensionData;
-
- fPacked = Allocate ( &d );
- #if defined ( INTERNAL_CHECKS )
- ASSERT ( IsValidInternal () );
- #endif
- }
-
-
- /***********************************|****************************************/
-
- TDSSpec::TDSSpec ( const TCreationID& cid, const TRLI& rli,
- OSType extensionType, const void* extensionData, unsigned long extensionLength ) :
- fPacked ( nil ),
- fUnpacked ( nil )
- {
- RecordID r;
- DSSpec d;;
-
- r.rli = (PackedRLI*) (const PackedRLI*) rli;
- r.local.cid = (CreationID&) (const CreationID&) cid;
- r.local.recordName = nil;
- r.local.recordType = nil;
-
- d.entitySpecifier = & r;
- d.extensionType = extensionType;
- d.extensionSize = extensionLength;
- d.extensionValue = (char*) extensionData;
-
- fPacked = Allocate ( &d );
- #if defined ( INTERNAL_CHECKS )
- ASSERT ( IsValidInternal () );
- #endif
- }
-
- /***********************************|****************************************/
-
- TDSSpec::TDSSpec ( const LocalRecordID& localRecordID, const TPathName& p, const TDirectory& directory,
- OSType extensionType, const void* extensionData, unsigned long extensionLength ) :
- fPacked ( nil ),
- fUnpacked ( nil )
- {
- TRLI rli ( directory, p );
- RecordID r;
- DSSpec d;
-
- r.rli = (PackedRLI*) (const PackedRLI*) rli;
- OCECopyCreationID(&localRecordID.cid, &r.local.cid);
- r.local.recordName = localRecordID.recordName;
- r.local.recordType = localRecordID.recordType;
-
- d.entitySpecifier = & r;
- d.extensionType = extensionType;
- d.extensionSize = extensionLength;
- d.extensionValue = (char*) extensionData;
-
- fPacked = Allocate ( &d );
- #if defined ( INTERNAL_CHECKS )
- ASSERT ( IsValidInternal () );
- #endif
- }
-
- /***********************************|****************************************/
-
- TDSSpec::TDSSpec ( const LocalRecordID& localRecordID, const DNodeNum node, const TDirectory& directory,
- OSType extensionType, const void* extensionData, unsigned long extensionLength ):
- fPacked ( nil ),
- fUnpacked ( nil )
- {
- TRLI rli ( directory, node );
- RecordID r;
- DSSpec d;;
-
- r.rli = (PackedRLI*) (const PackedRLI*) rli;
- OCECopyCreationID(&localRecordID.cid, &r.local.cid);
- r.local.recordName = localRecordID.recordName;
- r.local.recordType = localRecordID.recordType;
-
- d.entitySpecifier = & r;
- d.extensionType = extensionType;
- d.extensionSize = extensionLength;
- d.extensionValue = (char*) extensionData;
-
- fPacked = Allocate ( &d );
- #if defined ( INTERNAL_CHECKS )
- ASSERT ( IsValidInternal () );
- #endif
- }
-
- /***********************************|****************************************/
-
- TDSSpec::TDSSpec ( const LocalRecordID& localRecordID, const TRLI& rli,
- OSType extensionType, const void* extensionData, unsigned long extensionLength ):
- fPacked ( nil ),
- fUnpacked ( nil )
- {
- RecordID r;
- DSSpec d;;
-
- r.rli = (PackedRLI*) (const PackedRLI*) rli;
- OCECopyCreationID(&localRecordID.cid, &r.local.cid);
- r.local.recordName = localRecordID.recordName;
- r.local.recordType = localRecordID.recordType;
-
- d.entitySpecifier = & r;
- d.extensionType = extensionType;
- d.extensionSize = extensionLength;
- d.extensionValue = (char*) extensionData;
-
- fPacked = Allocate ( &d );
- #if defined ( INTERNAL_CHECKS )
- ASSERT ( IsValidInternal () );
- #endif
- }
-
- /***********************************|****************************************/
-
- TDSSpec::~TDSSpec ()
- {
- Deallocate ();
- }
-
- /***********************************|****************************************/
-
- TDSSpec&
- TDSSpec::operator = ( const DSSpec* r )
- {
- #if defined ( INTERNAL_CHECKS )
- ASSERT ( r != nil );
- #endif
-
- if ( ASSERT ( fUnpacked != r ) )
- {
- Deallocate ();
- fPacked = Allocate ( r );
- #if defined ( INTERNAL_CHECKS )
- ASSERT ( IsValidInternal () );
- #endif
- }
-
- return *this;
- }
-
- /***********************************|****************************************/
-
- TDSSpec&
- TDSSpec::operator = ( const PackedDSSpec* r )
- {
- if ( ASSERT ( fPacked != r ) )
- {
- Deallocate ();
- fPacked = Allocate ( r );
- #if defined ( INTERNAL_CHECKS )
- ASSERT ( IsValidInternal () );
- #endif
- }
-
- return *this;
- }
-
- /***********************************|****************************************/
-
- Boolean
- TDSSpec::operator == ( const DSSpec* r ) const
- {
- #if defined ( INTERNAL_CHECKS )
- if ( ASSERT ( IsValidInternal ( r ) ) )
- #endif
- if ( ASSERT ( ValidateUnpackedAndCheck () ) )
- return ::OCEEqualDSSpec ( fUnpacked, r );
-
- return false;
- }
-
- /***********************************|****************************************/
-
- Boolean TDSSpec::operator == ( const PackedDSSpec* p ) const
- {
- #if defined ( INTERNAL_CHECKS )
- if ( ASSERT ( IsValidInternal ( p ) ) )
- #endif
- if ( ASSERT ( IsValidInternal ( fPacked ) ) )
- return ::OCEEqualPackedDSSpec ( fPacked, p );
-
- return false;
- }
-
- /***********************************|****************************************/
-
- Boolean
- TDSSpec::Adopt ( PackedDSSpec* p )
- {
- ASSERT_RETURN_ZERO ( IsValid ( p ) && ( p != fPacked ) );
- Deallocate ();
- fPacked = p;
- return true;
- }
-
- /***********************************|****************************************/
-
- Boolean
- TDSSpec::Set ( const DSSpec* r )
- {
- // it is quite possible that the DSSpec* passed in could
- // be our unpacked cache, so be careful about deleting or
- // invalidating or unpacked cache or deleting our pack storage!
-
- #if defined ( INTERNAL_CHECKS )
- ASSERT_RETURN_ZERO ( IsValidInternal ( r ) );
- #endif
- PackedDSSpec* newPacked = Allocate ( r );
- #if defined ( INTERNAL_CHECKS )
- ASSERT_RETURN_ZERO ( IsValidInternal ( newPacked ) );
- #endif
- Deallocate ();
- fPacked = newPacked;
- return true;
- }
-
- /***********************************|****************************************/
-
- Boolean
- TDSSpec::Set ( const PackedRLI* rli )
- {
- #if defined ( INTERNAL_CHECKS )
- ASSERT_RETURN_ZERO ( TRLI::IsValid ( rli ) );
- #endif
- ASSERT_RETURN_ZERO ( ValidateUnpackedAndCheck () );
- PackedRLI* prevRLI = fUnpacked->entitySpecifier->rli;
- fUnpacked->entitySpecifier->rli = (PackedRLI*) rli;
-
- if ( Set ( fUnpacked ) )
- {
- return true;
- }
- else
- {
- fUnpacked->entitySpecifier->rli = prevRLI;
- return false;
- }
- }
-
- /***********************************|****************************************/
-
- Boolean
- TDSSpec::SetRecordName ( const TRString& string )
- {
- ASSERT_RETURN_ZERO ( ValidateUnpackedAndCheck () );
- RString* prevName = fUnpacked->entitySpecifier->local.recordName;
- fUnpacked->entitySpecifier->local.recordName = (RString*) (const RString*) string;
-
- if ( Adopt ( Allocate ( fUnpacked ) ) )
- {
- return true;
- }
- else
- {
- fUnpacked->entitySpecifier->local.recordName = prevName;
- return false;
- }
- }
-
- /***********************************|****************************************/
-
- Boolean
- TDSSpec::GetRecordName ( TRString& string ) const
- {
- ASSERT_RETURN_ZERO ( ValidateUnpackedAndCheck () );
- string = fUnpacked->entitySpecifier->local.recordName;
- return true;
- }
-
- /***********************************|****************************************/
-
- Boolean
- TDSSpec::SetRecordType ( const TRString& string )
- {
- ASSERT_RETURN_ZERO ( ValidateUnpackedAndCheck () );
- RString* prevType = fUnpacked->entitySpecifier->local.recordType;
- fUnpacked->entitySpecifier->local.recordType = (RString*) (const RString*) string;
-
- if ( Adopt ( Allocate ( fUnpacked ) ) )
- {
- return true;
- }
- else
- {
- fUnpacked->entitySpecifier->local.recordType = prevType;
- return false;
- }
- }
-
- /***********************************|****************************************/
-
- Boolean
- TDSSpec::GetRecordType ( TRString& string ) const
- {
- ASSERT_RETURN_ZERO ( ValidateUnpackedAndCheck () );
- string = fUnpacked->entitySpecifier->local.recordType;
- return true;
- }
-
- /***********************************|****************************************/
-
- Boolean
- TDSSpec::SetCreationID ( const TCreationID& cid )
- {
- ASSERT_RETURN_ZERO ( ValidateUnpackedAndCheck () );
- CreationID prevID = fUnpacked->entitySpecifier->local.cid;
- fUnpacked->entitySpecifier->local.cid = (CreationID&) (const CreationID&) cid;
-
- if ( Adopt ( Allocate ( fUnpacked ) ) )
- {
- return true;
- }
- else
- {
- fUnpacked->entitySpecifier->local.cid = prevID;
- return false;
- }
- }
-
- /***********************************|****************************************/
-
- Boolean
- TDSSpec::GetCreationID ( TCreationID& cid ) const
- {
- ASSERT_RETURN_ZERO ( ValidateUnpackedAndCheck () );
- cid = fUnpacked->entitySpecifier->local.cid;
- return true;
- }
-
- /***********************************|****************************************/
-
- Boolean
- TDSSpec::SetNode ( const DNodeNum node )
- {
- ASSERT_RETURN_ZERO ( ValidateUnpackedAndCheck () );
- TRLI rli ( fUnpacked->entitySpecifier->rli );
- rli.SetNode ( node );
- return Set ( rli );
- }
-
- /***********************************|****************************************/
-
- DNodeNum
- TDSSpec::GetNode () const
- {
- ASSERT_RETURN_ZERO ( ValidateUnpackedAndCheck () );
- TRLI rli ( fUnpacked->entitySpecifier->rli );
- return rli.GetNode ();
- }
-
- /***********************************|****************************************/
-
- Boolean
- TDSSpec::SetPathName ( const TPathName& path )
- {
- ASSERT_RETURN_ZERO ( ValidateUnpackedAndCheck () );
- TRLI rli ( fUnpacked->entitySpecifier->rli );
- rli.SetPathName ( path );
- return Set ( rli );
- }
-
- /***********************************|****************************************/
-
- Boolean
- TDSSpec::GetPathName ( TPathName& path ) const
- {
- ASSERT_RETURN_ZERO ( ValidateUnpackedAndCheck () );
- TRLI rli ( fUnpacked->entitySpecifier->rli );
- return rli.GetPathName ( path );
- }
-
- /***********************************|****************************************/
-
- Boolean
- TDSSpec::SetDirectory ( const TDirectory& directory )
- {
- ASSERT_RETURN_ZERO ( ValidateUnpackedAndCheck () );
- TRLI rli ( fUnpacked->entitySpecifier->rli );
- rli.SetDirectory ( directory );
- return Set ( rli );
- }
-
- /***********************************|****************************************/
-
- Boolean
- TDSSpec::GetDirectory ( TDirectory& directory ) const
- {
- ASSERT_RETURN_ZERO ( ValidateUnpackedAndCheck () );
- TRLI rli ( fUnpacked->entitySpecifier->rli );
- return rli.GetDirectory ( directory );
- }
-
- /***********************************|****************************************/
-
- Boolean
- TDSSpec::SetRLI ( const TRLI& rli )
- {
- return Set ( rli );
- }
-
- /***********************************|****************************************/
-
- Boolean
- TDSSpec::GetRLI ( TRLI& rli ) const
- {
- ASSERT_RETURN_ZERO ( ValidateUnpackedAndCheck () );
- rli = TRLI ( fUnpacked->entitySpecifier->rli );
- return true;
- }
-
- /***********************************|****************************************/
-
- TDSSpec::operator const DSSpec* () const
- {
- ValidateUnpackedAndCheck ();
- return fUnpacked;
- }
-
- /***********************************|****************************************/
-
- TDSSpec::operator const DSSpec& () const
- {
- ValidateUnpacked ();
- return *fUnpacked;
- }
-
- /***********************************|****************************************/
-
- OSType TDSSpec::GetExtensionType () const
- {
- ValidateUnpacked ();
- if ( fUnpacked )
- return fUnpacked->extensionType;
- else
- return kOCEInvalidDSSpec;
- }
-
- /***********************************|****************************************/
-
- unsigned long TDSSpec::GetExtensionSize () const
- {
- ValidateUnpacked ();
- if ( fUnpacked )
- return fUnpacked->extensionSize;
- else
- return 0;
- }
-
- /***********************************|****************************************/
-
- const void * TDSSpec::GetExtensionValue () const
- {
- ValidateUnpacked ();
- if ( fUnpacked )
- return (const void *) fUnpacked->extensionValue;
- else
- return 0;
- }
-
- /***********************************|****************************************/
-
- Boolean
- TDSSpec::Write ( TAbstractFile& f ) const
- {
- #if defined ( INTERNAL_CHECKS )
- ASSERT_RETURN_ZERO ( IsValidInternal () );
- #endif
- unsigned short physicalSize = GetPhysicalSize ( fPacked );
- ASSERT_RETURN_ZERO ( f.Write ( physicalSize ) == noErr );
- ASSERT_RETURN_ZERO ( f.WriteDataIgnore ( fPacked, physicalSize ) == noErr );
- return true;
- }
-
- /***********************************|****************************************/
-
- Boolean
- TDSSpec::Read ( TAbstractFile& f )
- {
- unsigned short physicalSize = 0;
- ASSERT_RETURN_ZERO ( f.Read ( physicalSize ) == noErr );
- ASSERT_RETURN_ZERO ( physicalSize >= sizeof ( ProtoPackedDSSpec ) );
- PackedDSSpec* newPacked = Allocate ( physicalSize );
- ASSERT_RETURN_ZERO ( newPacked != nil );
- ASSERT_RETURN_ZERO ( f.ReadDataIgnore ( newPacked, physicalSize ) == noErr );
- Deallocate ();
- fPacked = newPacked;
- #if defined ( INTERNAL_CHECKS )
- ASSERT_RETURN_ZERO ( IsValidInternal () );
- #endif
- return true;
- }
-
- /***********************************|****************************************/
-
- ostream&
- TDSSpec::operator >> ( ostream& s ) const
- {
- if ( ASSERT ( ValidateUnpackedAndCheck () ) )
- {
- s << "rli: " << fUnpacked->entitySpecifier->rli;
- s << "\ncid: " << fUnpacked->entitySpecifier->local.cid;
- s << ", recordName: " << fUnpacked->entitySpecifier->local.recordName;
- s << ", recordType: " << fUnpacked->entitySpecifier->local.recordType;
- }
- else
- {
- s << "fPacked: " << fPacked;
- }
-
- return s;
- }
-
-
-
-
- /***********************************|****************************************/
-
- static void Print ( ostream& s, const OSType x )
- {
- union { OSType o; char s [ 5 ]; } u;
-
- u.o = x;
- u.s [ 4 ] = '\0';
-
- s << '‘' << u.s << '’';
- }
-
- /***********************************|****************************************/
-
- ostream& operator << ( ostream& s, const RString* x )
- {
- if ( x )
- s << *x;
- else
- s << "<NIL>";
-
- return s;
- }
-
- /***********************************|****************************************/
-
- ostream& operator << ( ostream& s, const RString& x )
- {
- const unsigned short p = x.dataLength;
-
- s << '[';
-
- if ( p > 0 )
- {
- Byte c = ( (RString&) x ).body [ p ];
- ( (RString&) x ).body [ p ] = '\0';
- s << (const char*) x.body;
- ( (RString&) x ).body [ p ] = c;
- }
-
- if ( x.charSet != smRoman )
- s << '(' << (short) x.charSet << ')';
-
- return s << ']' << flush;
- }
-
- /***********************************|****************************************/
-
- ostream& operator << ( ostream& st, const CreationID& xa )
- {
- st << (unsigned long) xa.source;
- return st;
- }
-
- /***********************************|****************************************/
-
- #if 0
- ostream& operator << ( ostream& s, const CreationID* x )
- {
- if ( x )
- return s << *x;
- else
- return s << "<NIL>";
- }
- #endif
-
- /***********************************|****************************************/
-
- #if 1
- ostream& operator << ( ostream& s, const PackedPathName* x )
- {
- if ( x )
- {
- s << *x;
- }
- else
- s << "<NIL>";
-
- return s;
- }
- #endif
-
- /***********************************|****************************************/
-
- ostream& operator << ( ostream& s, const PackedPathName& x )
- {
- if ( ::OCEIsNullPackedPathName ( &x ) )
- {
- s << "<NULL PATHNAME>";
- }
- else
- {
- unsigned short count = (x.dataLength > 0) ? ::OCEDNodeNameCount ( &x ) : 0;
- ConstRStringPtr* r = (ConstRStringPtr*) FAILNewPtrClear ( count * sizeof ( ConstRStringPtr ) );
-
- if ( ASSERT ( r != nil ) )
- {
- if ( ASSERT ( ::OCEUnpackPathName ( &x, (RString* const *) r, count ) == count ) )
- {
- for ( unsigned short index = 0; index < count; index++ )
- {
- if ( index > 0 )
- s << ':';
-
- s << r [ index ];
- }
- }
-
- ::DeallocatePtr( (Ptr) r );
- #if defined ( INTERNAL_CHECKS )
- ASSERT ( MemError () == noErr );
- #endif
- }
- }
-
- return s;
- }
-
- /***********************************|****************************************/
-
- ostream& operator << ( ostream& s, const DirDiscriminator* x )
- {
- if ( x )
- return s << *x;
- else
- return s << "<NIL>";
- }
-
- /***********************************|****************************************/
-
- ostream& operator << ( ostream& s, const DirDiscriminator& x )
- {
- Print ( s, (const OSType) x.signature );
-
- if ( x.misc != 0 )
- s << " (" << x.misc << ')';
-
- return s;
- }
-
- /***********************************|****************************************/
-
- #ifndef THINK_CPLUS
- ostream& operator << ( ostream& s, const DirectoryName* x )
- {
- if ( x )
- return s << *x;
- else
- return s << "<NIL>";
- }
- #endif
-
- /***********************************|****************************************/
-
- ostream& operator << ( ostream& s, const DirectoryName& x )
- {
- const unsigned short p = x.dataLength;
-
- s << '[';
-
- if ( p > 0 )
- {
- Byte c = ( (RString&) x ).body [ p ];
- ( (RString&) x ).body [ p ] = '\0';
- s << (const char*) x.body;
- ( (RString&) x ).body [ p ] = c;
- }
-
- if ( x.charSet != smRoman )
- s << '(' << (short) x.charSet << ')';
-
- return s << ']' << flush;
- }
-
- /***********************************|****************************************/
-
- ostream& operator << ( ostream& s, const RLI* x )
- {
- if ( x )
- return s << *x;
- else
- return s << "<NIL>";
- }
-
- /***********************************|****************************************/
-
- ostream& operator << ( ostream& s, const RLI& x )
- {
- s << "directoryName:";
- operator << ( s, * (RStringPtr) x.directoryName );
- s << ", discriminator:";
- operator << ( s, x.discriminator );
- s << ", dNodeNumber:" << x.dNodeNumber << ", path:" << x.path;
- return s;
- }
-
- /***********************************|****************************************/
-
- ostream& operator << ( ostream& s, const PackedRLI* x )
- {
- if ( x )
- return s << *x;
- else
- return s << "<NIL>";
- }
-
- /***********************************|****************************************/
-
- ostream& operator << ( ostream& s, const PackedRLI& x )
- {
- RLI rli;
- ::OCEUnpackRLI ( &x, &rli );
- operator << ( s, rli );
- return s ;
- }
-
- /***********************************|****************************************/
-
- ostream& operator << ( ostream& s, const RecordID* x )
- {
- if ( x )
- return s << *x;
- else
- return s << "<NIL>";
- }
-
- /***********************************|****************************************/
-
- ostream& operator << ( ostream& s, const RecordID& x )
- {
- s << "recordName:" << x.local.recordName << ", recordType:" << x.local.recordType;
- s << " rli: {" << x.rli << "}, cid:" << hex << x.local.cid.source << " " << hex << x.local.cid.seq << dec;
- return s;
- }
-
- /***********************************|****************************************/
-
- ostream& operator << ( ostream& s, const PackedRecordID* x )
- {
- if ( x )
- return s << *x;
- else
- return s << "<NIL>";
- }
-
- /***********************************|****************************************/
-
- ostream& operator << ( ostream& s, const PackedRecordID& x )
- {
- RecordID r;
- ::OCEUnpackRecordID ( &x, &r );
- // return s << r;
- return s << "NOT IMPLEMENTED";
- }
-
- /***********************************|****************************************/
-